package com.ruoyi.villagers.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.villagers.domain.VigCard;
import com.ruoyi.villagers.mapper.VigCardMapper;
import com.ruoyi.villagers.service.IVigCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.smartcardio.Card;
import java.util.List;

@Service
public class VigCardServiceImpl implements IVigCardService {
    /**
     * 如果调用其他模块，注入service;
     */
    @Autowired
    private VigCardMapper vigCardMapper;


    @Override
    public List<VigCard> selectCardList(VigCard card) {
        return vigCardMapper.selectCardList(card);
    }

    @Override
    public int insertCard(VigCard card) {
        return vigCardMapper.insertCard(card);
    }

    /**
     * 检验身份证号是否重复
     * @param card 身份证信息
     * @return
     */
    @Override
    public String checkCardIdUnique(VigCard card) {
        Long cardPid = StringUtils.isNull(card.getCardPid()) ? -1L : card.getCardPid();
        VigCard info = vigCardMapper.checkCardIdUnique(card.getCardPid());
        if (StringUtils.isNotNull(info) && info.getCardPid().longValue() != cardPid.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }


    /**
     * 修改保存身份证信息
     *
     * @param card 身份证信息
     * @return 结果
     */
    @Override
    public int updateCard(VigCard card) {
        return vigCardMapper.updateCard(card);
    }




    /**
     * 通过身份证ID查询身份证信息
     *
     * @param cardId 身份证ID
     * @return 角色对象信息
     */
    @Override
    public VigCard selectCardById(String cardId) {
        return vigCardMapper.selectCardById(cardId);
    }


    /**
     * 删除身份证信息
     *
     * @param cardId 身份证ID
     * @return 结果
     */
    @Override
    public int deleteCardById(String cardId) {
        return vigCardMapper.deleteCardById(cardId);
    }


    /**
     * 批量删除身份证信息
     *
     * @param cardIds 需要删除的身份证ID
     * @return 结果
     * @throws Exception 异常
     */
    @Override
    public int deleteCardByIds(String[] cardIds) {

        return vigCardMapper.deleteCardByIds(cardIds);
    }

    @Override
    public List<VigCard> selectCardAll() {
        return vigCardMapper.selectCardAll();
    }


}
